package com.wingscode.modules.common.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wingscode.common.utils.PageUtils;
import com.wingscode.common.utils.Query;
import com.wingscode.modules.common.dao.UserOrderDao;
import com.wingscode.modules.common.entity.UserOrderEntity;
import com.wingscode.modules.common.service.UserOrderService;
import com.wingscode.modules.sys.form.ServiceQueryForm;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service("userOrderService")
public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrderEntity> implements UserOrderService {

    @Override
    public PageUtils orderList(Map<String, Object> params) {
        Integer userId = null, agentId = null;
        if (params.containsKey("userId"))
            userId = Integer.parseInt(params.get("userId").toString());
        if (params.containsKey("agentId"))
            agentId = Integer.parseInt(params.get("agentId").toString());

        IPage<UserOrderEntity> page = this.baseMapper.orderList(new Query<UserOrderEntity>().getPage(params), userId, agentId);

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(ServiceQueryForm form) {
        Map<String, Object> params = new HashMap<>();
        params.put("page", form.getPage());
        params.put("limit", form.getLimit());

        IPage<UserOrderEntity> page = this.baseMapper.queryPage(new Query<UserOrderEntity>().getPage(params), form.getMobile(), form.getCompany(),
                form.getNumber(), form.getStartTime(), form.getEndTime(), form.getSource(), form.getType(), form.getState());

        return new PageUtils(page);
    }

    @Override
    public UserOrderEntity orderInfo(Integer id) { return this.baseMapper.orderInfo(id); }

}
